PHP8.3.7をmacOS Sonomaにphpenvでインストールする
以下で解決してくださってた......感謝や🙏
要はicu4c 59+以上ではC++11でのビルドが必要だから CXXFLAGS="-std=c++11"を指定されてしまってるから起きてた問題で、とはいえPHP側としてはext-intlをビルドするのにC++17が必要やで〜〜って言ってるんですよね。何が正しいんや......
*
code:console
configure: error: *** A compiler with support for C++17 language features is required.
これ、8.3.7でconfigureをする中でicuに関する各種バージョンチェックを行う箇所に修正が入ったようなんですが、そのチェック処理にバグがあってicuがC++17を必要としたバージョンでなくてもC++17対応しているgccを必要としてしまっているらしいです。
(とはいえ、そもそもmacOS Sonomaに入ってるgccは当然C++17に対応しているはずなんですけど、configureした際に「対応してねえけど」って言われるんですよねえ......なんでなんだろ)
以下のissueとかも読んでるけど、解決したっぽいのに今回のような環境だと直らず。
Homebrewでgccを入れて、 CXX="$(brew --prefix gcc)/bin/g++-14" とかで指定して動かしてみたけど変化なし。そもそもgcc@9くらいからC++17はサポートされてるはずなので、別にXCode Command Line Toolsで入れられるgcc@15でもHomebrewで入れられるgcc@14でも十分なはずなんだけどなあ.....
念のためだけど、以下を参考にワンライナーを用意して動かしてみたけど、ちゃんとC++17相当になってた。ホントかわからんけど......
code:shell
echo "#include <iostream>\nint main() { std::cout << __cplusplus << std::endl; return 0; }" 1>/dev/null | $(brew --prefix gcc)/bin/g++-14 -x c++ -o ./tmp.out -std=c++17 - && ./tmp.out && rm ./tmp.out
なんか、以下とかを参照するとmacOSのgccコマンドはApple Clangってやつで、本来のGCCとは違う可能性がある......?
だとするとHomebrew GCCなら上手くいく可能性ある......?と思って CXX に指定しても、結局は以下のようなエラーになる。謎い。
checking whether /opt/homebrew/opt/gcc/bin/g++-14 supports C++17 features with -std=c++17... no
もしかしてphp-buildのせいだったりする......?みたいな気持ちで、php-buildだとconfigureが失敗してるsourceを使って以下のようにconfigureを実行してみたら通ってたりする...... optionsの渡り方が違うのか、ビルドに利用するライブラリがシェルとは違って上手く参照できてないのか、php-build内で参照してるgccがダメなのか、はたまた......みたいなのをphp-buildを読みつつphp-buildコマンドで直接実行したりして試してもよいのかもしれない。 #nextmove code:shell
PKG_CONFIG_PATH="$(brew --prefix icu4c)/lib/pkgconfig:$(brew --prefix libjpeg)/lib/pkgconfig:$(brew --prefix oniguruma)/lib/pkgconfig:$(brew --prefix libedit)/lib/pkgconfig" ./configure $(cat $(phpenv root)/plugins/php-build/share/php-build/default_configure_options | tr "\n" " ") --with-jpeg --with-zlib-dir=$(brew --prefix zlib) --with-bz2=$(brew --prefix bzip2) --with-curl=$(brew --prefix curl) --with-iconv=$(brew --prefix libiconv) --with-libedit --with-zip=$(brew --prefix libzip) --with-openssl=$(brew --prefix openssl@1.1) --with-tidy=$(brew --prefix tidy-html5)
以下はまだ整理できてない。
code:shell
PKG_CONFIG_PATH="$(brew --prefix icu4c)/lib/pkgconfig:$(brew --prefix libjpeg)/lib/pkgconfig:$(brew --prefix oniguruma)/lib/pkgconfig:$(brew --prefix libedit)/lib/pkgconfig" PHP_BUILD_CONFIGURE_OPTS="$(cat $(phpenv root)/plugins/php-build/share/php-build/default_configure_options | tr "\n" " ") --with-jpeg --with-zlib-dir=$(brew --prefix zlib) --with-bz2=$(brew --prefix bzip2) --with-curl=$(brew --prefix curl) --with-iconv=$(brew --prefix libiconv) --with-libedit --with-zip=$(brew --prefix libzip) --with-openssl=$(brew --prefix openssl@1.1) --with-tidy=$(brew --prefix tidy-html5)" $(phpenv root)/plugins/php-build/bin/php-build -v -k --ini development 8.3.8 /tmp/php-8.3.8
This function sets and unsets arguments for configure. Pass it the -D option to unset the argument given in $2. Otherwise the first argument is the name of the option and the second argument contains the optional value.
これはあくまで内部で利用してるfunction configure_option()に渡せるオプションなのか......ソースコードを読むと前述されてるdefault_configure_optionsファイルの値が読み込まれてるCONFIGURE_OPTIONSって変数に追加したり削除したりを操作してるみたい。たぶん直接configureするのとphp-buildを介するのとの違いはこの辺っぽいなあ
参考